<?php

namespace app\admin\model\detection;

use think\Model;


class Orders extends Model
{

    

    

    // 表名
    protected $name = 'check_order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
        'genderdata_text',
        'checktime_text',
        'is_diving_text',
        'gettime_text',
        'begintime_text',
        'overtime_text',
        'look_check_text',
        'low_check_text',
        'obd_check_text',
        'huan_check_text',
        'an_check_text',
        'san_check_text',
        'paytime_text',
        'sliptime_text',
        'check_images_text',
        'attachfile_text',
    ];

    public function getAttachfileTextAttr($value, $data)
    {
        $temp = [];
        if(isset($data['attachfile']) && !empty($data['attachfile']))
        {
            $temp = explode(',',$data['attachfile']);
            foreach ($temp as $key => &$value) {
                $value = request()->domain().$value;
            }
        }
        return  $temp;
    }
    public function getCheckImagesTextAttr($value, $data)
    {
        $temp = [];
        if(isset($data['check_images']) && !empty($data['check_images']))
        {
            $temp = explode(',',$data['check_images']);
            foreach ($temp as $key => &$value) {
                $value = request()->domain().$value;
            }
        }
        return  $temp;
    }
    
    public function getStatusList()
    {
        return ['-1' => __('已取消'), '0' => __('待支付'), '1' => __('已接单'), '2' => __('检测中'), '3' => __('待评论'), '4' => __('已完成')];
    }

    public function getGenderdataList()
    {
        return ['male' => __('Genderdata male'), 'female' => __('Genderdata female')];
    }

    public function getIsDivingList()
    {
        return ['0' => __('Is_diving 0'), '1' => __('Is_diving 1')];
    }

    public function getLookCheckList()
    {
        return ['0' => __('检测中'), '1' => __('已通过'), '2' => __('未通过'), '3' => __('已挂起')];
    }

    public function getLowCheckList()
    {
        return ['0' => __('检测中'), '1' => __('已通过'), '2' => __('未通过'), '3' => __('已挂起')];
    }

    public function getObdCheckList()
    {
        return ['0' => __('检测中'), '1' => __('已通过'), '2' => __('未通过'), '3' => __('已挂起')];
    }

    public function getHuanCheckList()
    {
        return ['0' => __('检测中'), '1' => __('已通过'), '2' => __('未通过'), '3' => __('已挂起')];
    }

    public function getAnCheckList()
    {
        return ['0' => __('检测中'), '1' => __('已通过'), '2' => __('未通过'), '3' => __('已挂起')];
    }

    public function getSanCheckList()
    {
        return ['0' => __('检测中'), '1' => __('已通过'), '2' => __('未通过'), '3' => __('已挂起')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ?: ($data['status'] ?? '');
        $list = $this->getStatusList();
        return $list[$value] ?? '';
    }


    public function getGenderdataTextAttr($value, $data)
    {
        $value = $value ?: ($data['genderdata'] ?? '');
        $list = $this->getGenderdataList();
        return $list[$value] ?? '';
    }


    public function getChecktimeTextAttr($value, $data)
    {
        $value = $value ?: ($data['checktime'] ?? '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }
    public function getSliptimeTextAttr($value, $data)
    {
        $value = $value ?: ($data['sliptime'] ?? '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }


    public function getIsDivingTextAttr($value, $data)
    {
        $value = $value ?: ($data['is_diving'] ?? '');
        $list = $this->getIsDivingList();
        return $list[$value] ?? '';
    }


    public function getGettimeTextAttr($value, $data)
    {
        $value = $value ?: ($data['gettime'] ?? '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getBegintimeTextAttr($value, $data)
    {
        $value = $value ?: ($data['begintime'] ?? '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getOvertimeTextAttr($value, $data)
    {
        $value = $value ?: ($data['overtime'] ?? '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getLookCheckTextAttr($value, $data)
    {
        $value = $value ?: ($data['look_check'] ?? '');
        $list = $this->getLookCheckList();
        return $list[$value] ?? '';
    }


    public function getLowCheckTextAttr($value, $data)
    {
        $value = $value ?: ($data['low_check'] ?? '');
        $list = $this->getLowCheckList();
        return $list[$value] ?? '';
    }


    public function getObdCheckTextAttr($value, $data)
    {
        $value = $value ?: ($data['obd_check'] ?? '');
        $list = $this->getObdCheckList();
        return $list[$value] ?? '';
    }


    public function getHuanCheckTextAttr($value, $data)
    {
        $value = $value ?: ($data['huan_check'] ?? '');
        $list = $this->getHuanCheckList();
        return $list[$value] ?? '';
    }


    public function getAnCheckTextAttr($value, $data)
    {
        $value = $value ?: ($data['an_check'] ?? '');
        $list = $this->getAnCheckList();
        return $list[$value] ?? '';
    }


    public function getSanCheckTextAttr($value, $data)
    {
        $value = $value ?: ($data['san_check'] ?? '');
        $list = $this->getSanCheckList();
        return $list[$value] ?? '';
    }


    public function getPaytimeTextAttr($value, $data)
    {
        $value = $value ?: ($data['paytime'] ?? '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setChecktimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setGettimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setBegintimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setOvertimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setPaytimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function admin()
    {
        return $this->belongsTo('app\admin\model\Admin', 'end_adminid', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function user()
    {
        return $this->belongsTo('app\admin\model\User', 'userid', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function detection()
    {
        return $this->belongsTo('app\admin\model\Detection', 'end_storeid', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
